<?php
function friendlyURL($string, $id){
    $string = preg_replace("`\[.*\]`U","",$string);
    $string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$string);
    $string = htmlentities($string, ENT_COMPAT, 'utf-8');
    $string = preg_replace( "`&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);`i","\\1", $string );
    $string = preg_replace( array("`[^a-z0-9]`i","`[-]+`") , "-", $string);
    $string = strtolower(trim($string, '-'));
    $string = $string.'__'.$id.'.html';
    
    return $string;
}


function sendauthemail($fromname,$fromaddr,$toaddr,$ccaddr,$subject,$bodymsg,$attachfilepath,$attachfilename,$levelint)
{	
	global $rootpath;

	//echo "In Email function test : $fromname,$fromaddr,$toaddr,$ccaddr,$subject,$bodymsg,$attachfilepath,$attachfilename,$levelint";
	
	$subject = trim($subject);
	if ($levelint==0)
	{
		require_once('htmlMimeMailroot.php');
	}
	elseif ($levelint==1)
	{
		require_once($rootpath.'includes/htmlMimeMail.php');
	}	
	
	$mail = new htmlMimeMail();	
	
	$sender_server='ssl://smtpout.asia.secureserver.net';
	$smtp_username='info@indianmobileprice.com';
	$smtp_password='123456';

	
	$mail->setHtml($bodymsg);
	$mail->setFrom(''.$fromname.' <'.$fromaddr.'>');
	$mail->setSubject($subject);
	$mail->setHeader('X-Mailer', 'HTML Mime mail class');
	$mail->setHeader('Date', date('D, d M y H:i  O'));			
	$mail->setSMTPParams(''.$sender_server.'', 465, ''.$sender_server.'',True,''.$smtp_username.'',''.$smtp_password.'');
	
	if ($attachfilename!="")
	{
		$attachment = $mail->getFile($attachfilepath);
		$mail->addAttachment($attachment, $attachfilename);
	}
	
	if ($ccaddr !="")
	{
		$mail->setCc($ccaddr);
	}	
	
	//put BCC email address of Mitesh if it is NOT ERROR EMAIL
	
	if($bLive)
	{
		//send a copy of email to Mitesh Soma except for error email - ONLINE SERVER
		if(substr(strtoupper($subject),0,5) != 'ERROR')
		{
			$b_send_admin_email = false;
			$arr_mail_subjects=array('Wholesale Trade','Contact Us','Can\'t Find What','Customer Service','Your friend','Get off');

			for($i_sub=0;$i_sub<count($arr_mail_subjects);$i_sub++)
			{
				$tmp_mail_subject = strtoupper($arr_mail_subjects[$i_sub]);
				if(substr(strtoupper($subject),0,strlen($tmp_mail_subject)) == $tmp_mail_subject)	
				{
					$b_send_admin_email = true;
					break;
				}
			}
			if($b_send_admin_email)
				$mail->setBcc('vishal.mehta@pulsesolutions.com');
			else
				$mail->setBcc('asd@gmail.com');	
		}
		else
			$mail->setBcc('');	
	}
	else
	{
		$mail->setBcc('');	
	}
	echo 'Hey';
	$result = $mail->send(array($toaddr), 'smtp');
	print_r($result);
	// These errors are only set if you're using SMTP to send the message
	if (!$result) 
	{
		$str="NOT SEND";
	} 
	else 
	{
		$str="SEND";
	}
}
?>